﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Web.Services;
using System.ServiceModel;
using eBayInterface.com.ebay.developer;

namespace eBayInterface
{

    public partial class Form1 : Form
    {
        private string endpoint = "https://api.ebay.com/wsapi";
        private string siteId = "0";
        private string appId = "BIGInter-6497-4934-862a-0edb36511b90"; // use your app ID 
        private string devId = "aa493a58-84f2-4d76-9b44-0c4f30658540"; // use your dev ID 
        private string certId = "61066c80-dfd3-4ed5-a0a5-35da99cc1127"; // use your cert ID 
        private string version = "605";
        private string token = "AgAAAA**AQAAAA**aAAAAA**1paqSQ**nY+sHZ2PrBmdj6wVnY+sEZ2PrA2dj6wAkYenDpOEqAidj6x9nY+seQ**JpkAAA**AAMAAA**nvhuxkEG6ycpK3ohDndUupRYXwinPYXl9L8B0/Z8o5CLfBVSYu/j2Ysj0q3f0+IxF7W1WNhTnF4SQKXnOuU+a91ss3k5wLPWD8MKeKpd5DDqCQ97fIm0Ow7gYX6Wd4zRnPF+nEKfkShXMrxGKHBGKIKGkQUN33PpVHzze8i1VwDHICPTop7rEPYoehOh9fZVEyj+4ikBIu12WjnybkRwVfR6wCKNenm6ZcxXah8eAZ02LPsAUAKyG4SuNgNoPaNepxvig+8zf7iaeA2c/kTf7yb3fmsQtxpxtR4snV15WqYyP8zRp8N/ISuyHxZO7FPkbw3YoE1GDA+rMDwJOnIiJr9fVFSW3sEnd6v8A7g9mlgC3/W1jmLVHr9Cb8BCUOn1IY5LddBHYVbkHuJ3lhnK4X6oDuvvhct8e2NspvLa6WZB1FUXnbaaIhvyiN1sQkf+vMtxG0NW1jxYnhRmoUXCO+/IzqurWfpTZHx5BMh1JrnabCnFE9lJSoNqjp0RFTjRSlSJ28wAwv45Gqgv6C7ep1zarEv+2mrU8y+n2tT1DJ5DN8lcd1un59VP0mi/gu9cc6pEnpveb/LOydO3v5Vmy6nL78IsL7QBNES+sR2XHKQ9GNT+xPk987nSvBd1oTb02V24tPgy/4EqEFhe47whmzpV8gWKIKuBvCh3ZSEKQGCGxtma5o5dlGyBNYkwLqdokh4MJ7W5Yet20Eu/Lqe6/+zom4yMgj4QEpvo8RlTKayKYWhd7DLG2q2LzLJLDMGD";

        public Form1()
        {
            InitializeComponent();
        //    comboBox1.Items.Add("Seller");
        //    comboBox1.Items.Add("Buyer");
            domainUpDown1.Items.Add("Seller");
            domainUpDown1.Items.Add("Buyer");


            comboBox2.Items.Add("SellerUserID");
            comboBox2.Items.Add("Buyer");

            comboBox1.Items.Add(new ComboBoxItem("Get my eBay Buying", 1));
            comboBox1.Items.Add(new ComboBoxItem("Get my eBay Selling", 2));
            comboBox1.Items.Add(new ComboBoxItem("Get eBay time", 99));

            //comboBox2.Items.Add(new ComboBoxItem("Get my eBay Buying", 1));
            //comboBox2.Items.Add(new ComboBoxItem("Get my eBay Selling", 2));
            //comboBox2.Items.Add(new ComboBoxItem("Get eBay time", 99));
            //You can get the selected value in following way-
            //int selectedValue = ((ComboBoxItem)myComboBox.SelectedItem).Value;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //example:
            //http://developer.ebay.com/DevZone/XML/docs/HowTo/FirstCall/MakingCallCSharp.html

            string callName = "GetOrders";
             
            StringBuilder messageLog = new StringBuilder("");

            // Build the request URL 
            string requestURL = endpoint
            + "?callname=" + callName
            + "&siteid=" + siteId
            + "&appid=" + appId
            + "&version=" + version
            + "&routing=default";
            // Create the service 
            eBayAPIInterfaceService service = new eBayAPIInterfaceService();
            // Assign the request URL to the service locator. 
            service.Url = requestURL;
            // Set credentials 
            service.RequesterCredentials = new CustomSecurityHeaderType();
            service.RequesterCredentials.eBayAuthToken = token;    // use your token 
            service.RequesterCredentials.Credentials = new UserIdPasswordType();
            service.RequesterCredentials.Credentials.AppId = appId;
            service.RequesterCredentials.Credentials.DevId = devId;
            service.RequesterCredentials.Credentials.AuthCert = certId;
            // Make the call to GeteBayOfficialTime 
            GetOrdersRequestType request = new GetOrdersRequestType();
            DateTime dateFrom = dateTimePicker1.Value;
            DateTime dateTo = dateTimePicker2.Value;
            request.Version = version;
            request.CreateTimeTo = dateTo;
            request.CreateTimeFrom = dateFrom;
            request.CreateTimeFromSpecified = true;
            request.CreateTimeToSpecified = true;
            request.OrderRole = TradingRoleCodeType.Buyer;
            request.OrderRoleSpecified = true;
            request.OrderStatus = OrderStatusCodeType.Completed;
            request.OrderStatusSpecified = true;
            //request.DetailLevel = DetailLevelCodeType.ReturnAll;
            request.ErrorHandling = ErrorHandlingCodeType.BestEffort;
            request.ErrorHandlingSpecified = true;
            request.ListingType = ListingTypeCodeType.Half;
            request.ListingTypeSpecified = true;
           // request.Pagination = PaginationType.Equals;
            GetOrdersResponseType response = service.GetOrders(request);
           // textBox1.Text = string.Format("{0}", response.Message);
 
            messageLog.Append("Message: ");
            messageLog.Append(response.Message);
            messageLog.Append("\r\nResponse: ");
            messageLog.Append(response.ReturnedOrderCountActual);
            messageLog.Append("\r\nACK: ");
            messageLog.Append(response.Ack);
            messageLog.Append("\r\nBUILD: ");
            messageLog.Append(response.Build);
           
            if (true == response.AckSpecified && (AckCodeType.Success == response.Ack || AckCodeType.Warning == response.Ack))
            {
                // print out the details of this Product
                foreach (OrderType Order in response.OrderArray)
                {
                    if (null != Order.SellerEmail)
                    {
                       
                        textBox8.Text = "The Title of this product is " + Order.SellerEmail;

                    }
                }
            } else if (true == response.AckSpecified && AckCodeType.Failure == response.Ack) 
            {
                foreach (ErrorType Error in response.Errors)
                {
                    if (null != Error.LongMessage)
                    {
                       // textBox4.Text = Error.LongMessage;
                        messageLog.Append("\r\nError: ");
                        messageLog.Append(Error.LongMessage);
                    }
                }
            }
            textBox8.Text = string.Format("{0}", messageLog);
        }

        private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
        {

        }

        private void dateTimePicker2_ValueChanged(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            textBox7.Text = dateTimePicker1.Value.Year.ToString();
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }
    }

    class ComboBoxItem
    {
        public string Name;
        public int Value;
        public ComboBoxItem(string Name, int Value)
        {
            this.Name = Name;
            this.Value = Value;
        }

        public override string ToString()
        {
            return this.Name;
        }
    }
}


//<?xml version="1.0" encoding="utf-8"?>
//<GetMyeBayBuying xmlns="urn:ebay:apis:eBLBaseComponents">
//<RequesterCredentials>
//<eBayAuthToken>AgAAAA**AQAAAA**aAAAAA**1paqSQ**nY+sHZ2PrBmdj6wVnY+sEZ2PrA2dj6wAkYenDpOEqAidj6x9nY+seQ**JpkAAA**AAMAAA**nvhuxkEG6ycpK3ohDndUupRYXwinPYXl9L8B0/Z8o5CLfBVSYu/j2Ysj0q3f0+IxF7W1WNhTnF4SQKXnOuU+a91ss3k5wLPWD8MKeKpd5DDqCQ97fIm0Ow7gYX6Wd4zRnPF+nEKfkShXMrxGKHBGKIKGkQUN33PpVHzze8i1VwDHICPTop7rEPYoehOh9fZVEyj+4ikBIu12WjnybkRwVfR6wCKNenm6ZcxXah8eAZ02LPsAUAKyG4SuNgNoPaNepxvig+8zf7iaeA2c/kTf7yb3fmsQtxpxtR4snV15WqYyP8zRp8N/ISuyHxZO7FPkbw3YoE1GDA+rMDwJOnIiJr9fVFSW3sEnd6v8A7g9mlgC3/W1jmLVHr9Cb8BCUOn1IY5LddBHYVbkHuJ3lhnK4X6oDuvvhct8e2NspvLa6WZB1FUXnbaaIhvyiN1sQkf+vMtxG0NW1jxYnhRmoUXCO+/IzqurWfpTZHx5BMh1JrnabCnFE9lJSoNqjp0RFTjRSlSJ28wAwv45Gqgv6C7ep1zarEv+2mrU8y+n2tT1DJ5DN8lcd1un59VP0mi/gu9cc6pEnpveb/LOydO3v5Vmy6nL78IsL7QBNES+sR2XHKQ9GNT+xPk987nSvBd1oTb02V24tPgy/4EqEFhe47whmzpV8gWKIKuBvCh3ZSEKQGCGxtma5o5dlGyBNYkwLqdokh4MJ7W5Yet20Eu/Lqe6/+zom4yMgj4QEpvo8RlTKayKYWhd7DLG2q2LzLJLDMGD</eBayAuthToken>
//</RequesterCredentials>
//<WonList>
//<Sort>SellerUserID</Sort>
//<IncludeNotes>1</IncludeNotes>
//</WonList>
//<DetailLevel>ReturnSummary</DetailLevel>
//<Version>607</Version>
//<WarningLevel>Low</WarningLevel>
//</GetMyeBayBuying>